#define LGOGL_CORE

#include "lgogl_init.h"
#include "lgogl_texture.h"
#include "lgogl_shader.h"
#include "lgogl_draw.h"
#include "lgogl_canvas.h"
#include "lgogl_vertex.h"
#include "lgogl_std.h"

#ifdef LG_WINDOWS
#include "lgogl_winpc.h"
#endif

static struct {
    LGOGLConfig config;
}gCtx;

static LGBackend backend = { 0 };

static int
init(LGConfig* config){
#ifdef LG_WINDOWS
    lgoglInitWinpcContext(config, &gCtx.config);
#endif
    lgoglInitStdContext(config, &gCtx.config);
    return 0;
}

static int
dispatch() {
#ifdef LG_WINDOWS
    return lgoglDispatchWinpc();
#endif

    return 0;
}


LGOGL_API LGBackend*
lgoglInit(LGOGLConfig* config){
    gCtx.config = *config;
    backend.init = init;
    backend.dispatch = dispatch;
#ifdef LG_WINDOWS
    backend.window = lgoglWinpcWindowBackend();
#endif
    backend.texture = lgoglTextureBackend();
    backend.shader = lgoglShaderBackend();
    backend.draw = lgoglDrawBackend();
    backend.canvas = lgoglCanvasBackend();
    backend.vertex = lgoglVertexBackend();
    backend.std = lgoglStdBackend();
    return &backend;
}